<?php
class JSitemap
{
    /**
     * 
     * header for rss 2.0
     * @param string $description
     */
    public static function getHeaderRss($description)
    {
        return '<?xml version="1.0" encoding="UTF-8" ?>' 
                . "\n" 
                . '<rss version="2.0">'
                . "\n"
                . " <channel>"
                . "\n"
                . "  <title>Interateitis blog`as</title>"
                . "\n"
                . "  <description>" . $description . "</description>"
                . "\n"
                . "  <link>http://www.interateitis.lt/blogas</link>"
                . "\n"
                . "  <lastBuildDate>".date('D, m F Y H:i:s O')." </lastBuildDate>"
                . "\n"
                . "  <pubDate>".date('D, m F Y H:i:s O')." </pubDate>"
                . "\n";
    }
    public static function getFooterRss()
    {
        return " </channel>\n</rss>\n";
    }
    /**
     * 
     * generetes one rss item
     * @param string $title
     * @param string $description
     * @param string $link
     * @param string $guid
     * @param formated date $date - (Mon, 06 Sep 2009 16:45:00 +0000)
     * @return string $string - one rss item
     */
    public static function getRssItem($title, $description, $link, $guid, $date)
    {
        $string = "    <item>\n";
        $string .= "      <title>" . $title . "</title>\n";
        $string .= "      <description>" . $description . "</description>\n";
        $string .= "      <link>" . $link . "</link>\n";
        $string .= "      <guid>" . $guid . "</guid>\n";
        $string .= "      <pubDate>" . date('D, m F Y H:i:s O', $date) . " </pubDate>\n";
        $string .= "    </item>\n";
        return $string;
    }
    /**
     * 
     * returns inner sitemap string for xml
     * @param string $loc - address of inner sitemap
     * @param string $lastmod - date
     */
    public static function getSitemapsLoc( $loc, $lastmod = 'notset' )
    {
        if($lastmod == 'notset')
        {
            $lastmod = date("Y-m-d");
        }
        $string = "  <sitemap>\n";
        $string .= "   <loc>" . $loc . "</loc>\n";
        $string .= "   <lastmod>" . $lastmod . "</lastmod>\n";
        $string .= "  </sitemap>\n";
        return $string;
    }
    /**
     * generates string for one link for sitemap
     * @param string $loc - absolute addres (link)
     * @param string $lastmod time (2011-11-05)
     * @param string $changefreq (chenging frequency)
     * @param string $priority 
     */
    public static function getUrlSitemap($loc, $lastmod, $changefreq, $priority )
    {
        if($lastmod == '')
        {
            $lastmod = date("Y-m-d");
        }else 
        {
            $lastmod = date("Y-m-d", $lastmod);
        }
        if($changefreq == '')
        {
            $changefreq = 'monthly';
        }
        if($priority == '')
        {
            $priority = '0.8';
        }
        $string = "  <url>\n";
        $string .= "   <loc>" . $loc . "</loc>\n";
        $string .= "   <lastmod>" . $lastmod . "</lastmod>\n";
        $string .= "   <changefreq>" . $changefreq . "</changefreq>\n";
        $string .= "   <priority>" . $priority . "</priority>\n   </url>";
        return $string;
    }
    /**
     * @return string
     * header of sitemap
     */
    public static function getHeader()
    {
        return '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . ' <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
    }
    /**
     * @return string
     * footer of sitemap
     */
    public static function getFooter()
    {
        return " </urlset>\n";
    }
    /**
     * 
     * header for index sitemap
     */
    public static function getHeaderIndex()
    {
        return ' <?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
    }
    
    public static function getFooterIndex()
    {
        return " </sitemapindex>\n";
    }
}